package com.kiln.juxingqs.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.global.commlib.network.data.JsonResult
import client.global.commlib.network.data.Ret
import com.kiln.juxingqs.api.bean.HangOrderRecord
import com.kiln.juxingqs.api.bean.Zcjl
import com.kiln.juxingqs.api.bean.ZrAndSgRet
import com.kiln.juxingqs.ui.viewmodel.MiddleVm


class GuadanViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)

    val isOneLoading = MutableLiveData<Boolean>(false)
    val pageOne = MutableLiveData<Int>(0)
    val callOne = MutableLiveData<JsonResult<Zcjl>>()
    val cancelRet = MutableLiveData<JsonResult<Ret>>()
    val queRenRet = MutableLiveData<JsonResult<Ret>>()

    val newQueRenRet = MutableLiveData<JsonResult<Ret>>()

    fun querenOrder(b: ZrAndSgRet.Order) {
        hold({
            server.buyer_confirm(
                "${b.order_id}"
            )
        }, {
            isShowing.value = true
        }, {
            queRenRet.value = it
        }, complete = {
            isShowing.value = false

        })
    }


    fun cancelOrder(b: HangOrderRecord.Order) {
        if (isOneLoading.value!!)
            return
        hold({
            server.revoke_hang_order("${b.id}")
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            cancelRet.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }


}